package com.yiyw.herostory.manage;

import com.yiyw.herostory.bo.UserBo;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @Author yiyw
 * @Description TODO
 * @Date 2022/8/14 14:35
 **/
public final class UserManage {

    private static Map<Integer, UserBo> userMap = new HashMap<>();

    private UserManage() {

    }

    public static void addUser(UserBo userBo) {
        userMap.put(userBo.getUserId(), userBo);
    }

    public static void removeUser(Integer userId) {
        if (null != userId) {
            userMap.remove(userId);
        }
    }

    /***
     * @author yiyw
     * @description 获取所有的玩家信息
     * @createTime  2022/8/14 14:41
     * @return java.util.List<com.yiyw.herostory.bo.UserBo>
     */
    public static List<UserBo> getAllUser() {
        return userMap.entrySet().stream().map(e -> e.getValue()).collect(Collectors.toList());
    }

    public static UserBo getUser(Integer userId) {
        if (userId == null) {
            return null;
        }
        UserBo userBo = userMap.get(userId);
        return userBo;
    }
}
